<template>
  <Dialog v-model="dialogVisible" :title="dialogTitle">
    <el-form ref="formRef" v-loading="formLoading" :model="formData" label-width="50px">
      <el-form-item label="原因:" prop="remarks">
        <el-input v-model="formData.remarks" placeholder="请输入阻塞用例的原因" type="textarea" rows="5"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script lang="ts" setup>
defineOptions({ name: 'Lock' })
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('提示') // 弹窗的标题
const formLoading = ref(false)
const formData = ref({} as any)
const formRef = ref()

/** 打开弹窗 */
const open = async () => {
  dialogVisible.value = true
  resetForm()
}

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    remarks: '',
  }
  formRef.value?.resetFields()
}
defineExpose({ open })

/** 提交表单 */
const emit = defineEmits(['success']) 
const submitForm = async () => {
  formLoading.value = true
  try {
    const data = formData.value
    dialogVisible.value = false
    emit('success',data)
  } finally {
    formLoading.value = false
  }
}
</script>
